from lib.base import Base
class RenameColumn(Base):
    
    def __init__(self, db, query):
        self._clear_attributes()
        self.db = db
        self.query = self._determine_attributes(query)

    def execute(self):
        if self.query == None:
            print "Database does not support operation"
        else:
            print "Running renaming column from: %s, column: %s to %s" % (self.table, self.column_name, self.new_name)
            self.db.execute(self.query.strip())
        return True

    def _determine_attributes(self, query):
        query = self._trim_table(query)
        query = self._trim_column_name(query)
        query = self._trim_new_name(query)
        self._build_dictionary(query)
        return self.db.format_rename_column(self.table, self.column_name, self.new_name, self.attributes)